package com.cloudweb.oa.service.impl;

import com.cloudweb.oa.api.IFormBlocklistService;
import com.cloudweb.oa.security.AuthUtil;
import com.cloudweb.oa.utils.ConstUtil;
import com.cloudwebsoft.framework.util.LogUtil;
import com.redmoon.oa.flow.FormDb;
import com.redmoon.oa.visual.FormDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.Date;

@Service
public class FormBlocklistService implements IFormBlocklistService {

    @Autowired
    private AuthUtil authUtil;

    @Override
    public boolean create(String ip) {
        FormDb fd = new FormDb();
        fd = fd.getFormDb("blocklist");
        FormDAO fdao = new FormDAO(fd);
        fdao.setFieldValue("ip", ip);
        fdao.setFieldValue("create_at", new Date());

        fdao.setFlowTypeCode(String.valueOf(System.currentTimeMillis())); // 流程类型编码，选填
        fdao.setCreator(authUtil.getUserName()); // 参数为用户名（创建记录者），必填
        fdao.setUnitCode(authUtil.getUserUnitCode() == null ? ConstUtil.DEPT_ROOT : authUtil.getUserUnitCode()); // 置单位编码，必填
        boolean re = false;
        try {
            re = fdao.create();
        } catch (SQLException throwables) {
            LogUtil.getLog(getClass()).error(throwables);
        }
        return re;
    }
}
